/*
 * @Author      : ZhouQiJun
 * @Date        : 2025-08-15 00:22:56
 * @LastEditors : ZhouQiJun
 * @LastEditTime: 2025-08-15 01:49:04
 * @Description : 设置遮罩
 */
import { type GisKey, KEY, Platform } from '@ol/define'
import { setupMask as olSetupMask } from '@ol/platform'
import type { MaskOptions } from '@ol/types'
import { merge } from 'es-toolkit'

// TODO 提供全局的默认配置
const defaultMaskOptions: Partial<MaskOptions> = {
  dataProjection: 'EPSG:4326',
  fitMask: true,
  shadowWidth: 10,
  shadowColor: 'red',
}

/**
 * 设置遮罩
 * @Author ZhouQiJun
 */
export default function setupMask(
  wktOrGeojson: string,
  options = defaultMaskOptions,
  key: GisKey = KEY,
  platform: Platform = Platform.OL,
) {
  const _options = merge(options, defaultMaskOptions)
  if (['ce', 'cesium'].includes(platform)) {
    return null
  }
  return olSetupMask(wktOrGeojson, _options, key)
}
